package com.shenfa.dao;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.shenfa.bean.SystemTranCode;
import com.shenfa.tools.SteelTools;

/**
 * 系统管理-交易代码管理 DAO
 * 
 * @author 张瑶
 * @date 2011-08-24
 */
public class SystemTranCodeDao {

	@Autowired
	private SqlMapClient sqlMapClient;

	/**
	 * 模糊查询模板主表信息
	 * 
	 * @param systemTranCode
	 *            系统管理-交易代码管理，T_S_TRAN_CODE[交易代码]对应
	 * @param skip
	 *            分页使用
	 * @param max
	 *            分页使用
	 * @return 模板主表信息
	 */
	@SuppressWarnings("unchecked")
	public List<SystemTranCode> selectSystemTranCode(SystemTranCode systemTranCode, int start, int limit) {

		List<SystemTranCode> list = null;
		try {
			list = sqlMapClient.queryForList("system_manager.selectSystemTranCode", systemTranCode, start, limit);
		} catch (SQLException e) {
			SteelTools.log(e.getMessage());
		}
		return list;
	}
	public int getCount(SystemTranCode systemTranCode) {

		int a;
		try {
			a = (Integer)sqlMapClient.queryForObject("system_manager.getstcCount", systemTranCode);
		} catch (SQLException e) {
			SteelTools.log(e.getMessage());
			return -1;
		}
		return a;
	}
	/**
	 * 验证交易代码主键唯一性
	 * @param systemTranCode
	 * @param start
	 * @param limit
	 * @return
	 */
	public int validateSystemTranCode(SystemTranCode systemTranCode) {

		try {
			return (Integer)sqlMapClient.queryForObject("system_manager.validateSystemTranCode", systemTranCode);
		} catch (SQLException e) {
			SteelTools.log(e.getMessage());
			return 1;
		}
	}

	/**
	 * 增加模板主表信息
	 * 
	 * @param systemTranCode
	 *            系统管理-交易代码管理，T_S_TRAN_CODE[交易代码]对应
	 * @return 增加是否成功，返回0则失败。
	 */
	public int insertSystemTranCode(SystemTranCode systemTranCode) {
		try {
			sqlMapClient.insert("system_manager.insertSystemTranCode", systemTranCode);
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}

	/**
	 * 更新模板主表信息
	 * 
	 * @param systemTranCode
	 *            系统管理-交易代码管理，T_S_TRAN_CODE[交易代码]对应
	 * @return 0 则表示更新失败。
	 */
	public int updateSystemTranCode(SystemTranCode systemTranCode) {
		try {
			sqlMapClient.update("system_manager.updateSystemTranCode", systemTranCode);
			return 1;
		} catch (SQLException e) {
			SteelTools.log(e.getMessage());
			return 0;
		}
	}

	/**
	 * 刪除模板主表信息
	 * 
	 * @param systemTranCode
	 *            系统管理-交易代码管理，T_S_TRAN_CODE[交易代码]对应
	 * @return 0 则表示刪除失败。
	 */
	public int deleteSystemTranCode(SystemTranCode systemTranCode) {
		try {
			sqlMapClient.delete("system_manager.deleteSystemTranCode", systemTranCode);
			return 1;
		} catch (SQLException e) {
			SteelTools.log(e.getMessage());
			return 0;
		}
	}

}
